home *** CD-ROM | disk | FTP | other *** search
/ Dream 55 / Amiga_Dream_55.iso / RISCOS / APPS / TEXT / PS / KIT-PS.ZIP / Kit PS / !PSUtils / pl / includeres < prev    next >
Text File  |  1997-01-24  |  1KB  |  54 lines

  1. @rem = '-*- Perl -*-
  2. @echo off
  3. perl -S %0.cmd %1 %2 %3 %4 %5 %6 %7 %8 %9
  4. goto endofperl
  5. ';
  6.  
  7. # includeres: include resources in PostScript file
  8. #
  9. # Copyright (C) Angus J. C. Duggan 1991-1995
  10. # See file LICENSE for details.
  11.  
  12. $prog = ($0 =~ s=.*/==);
  13.  
  14. %extn = ("font", ".pfa", "file", ".ps", "procset", ".ps", # resource extns
  15.      "pattern", ".pat", "form", ".frm", "encoding", ".enc");
  16. %type = ("%%BeginFile:", "file", "%%BeginProcSet:", "procset",
  17.      "%%BeginFont:", "font"); # resource types
  18.  
  19. sub filename {            # make filename for resource in @_
  20.    local($name);
  21.    foreach (@_) {        # sanitise name
  22.       s/[!()\$\#*&\\\|\`\'\"\~\{\}\[\]\<\>\?]//g;
  23.       $name .= $_;
  24.    }
  25.    $name =~ s@.*/@@;        # drop directories
  26.    die "Filename not found for resource ", join(" ", @_), "\n"
  27.       if $name =~ /^$/;
  28.    $name;
  29. }
  30.  
  31. while (<>) {
  32.    if (/^%%IncludeResource:/ || /^%%IncludeFont:/ || /^%%IncludeProcSet:/) {
  33.       local($comment, @res) = split(/\s+/);
  34.       local($type) = defined($type{$comment}) ? $type{$comment} : shift(@res);
  35.       local($name) = &filename(@res);
  36.       local($inc) = "<PSUtils$Dir>.ps"; # system include directory
  37.       if (open(RES, $name) || open(RES, "$name$extn{$type}") ||
  38.       open(RES, "$inc/$name") || open(RES, "$inc/$name$extn{$type}")) {
  39.      while (<RES>) {
  40.         print $_;
  41.      }
  42.      close(RES);
  43.       } else {
  44.      print "%%IncludeResource: ", join(" ", $type, @res), "\n";
  45.      print STDERR "Resource $name not found\n";
  46.       }
  47.    } else {
  48.       print $_;
  49.    }
  50. }
  51. __END__
  52. :endofperl
  53.  
  54.